package com.hcs.chenyu.chenyuusedmarket;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.hcs.chenyu.R;

public class balls extends AppCompatActivity {

    //需要适配的数据
    private String[] titles = { "basketball", "pingpang", "volleyball", "soccerball", "badminton",
            "tableball", "gaoerfu","bangqiu"};
    private String[] prices = { "10元以上", "10元以上", "10元以上", "10元以上", "10元以上",
            "10元以上", "10元以上","10元以上"};
    //图片集合
    private int[] icons = {R.drawable.basketball,R.drawable.pingpang,R.drawable.volleyball,
            R.drawable.soccerball,R.drawable.badminton,R.drawable.tableball,R.drawable.gaoerfu,R.drawable.bangqiu};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_balls);

        ListView mListViews = findViewById(R.id.list_viewballs);


        myBaseAdapter adapter = new myBaseAdapter();
        mListViews.setAdapter(adapter);


        mListViews.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @SuppressLint("ResourceType")
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println(position);
                switch (position){
                    case 0:
                        Intent intent = new Intent(balls.this, apple.class);
                        startActivity(intent);
                        break;
                    case 1:
                        Intent intent1 = new Intent(balls.this, carrot.class);
                        startActivity(intent1);
                        break;
                    case 2:
                        Intent intent2 = new Intent(balls.this, garlic.class);
                        startActivity(intent2);
                        break;
                    case 3:
                        Intent intent3 = new Intent(balls.this, potato.class);
                        startActivity(intent3);
                        break;
                    case 4:
                        Intent intent4 = new Intent(balls.this, tomato.class);
                        startActivity(intent4);
                        break;
                    case 5:
                        Intent intent5 = new Intent(balls.this, cucumber.class);
                        startActivity(intent5);
                        break;
                    case 6:
                        Intent intent6 = new Intent(balls.this, vegetablemore.class);
                        startActivity(intent6);
                        break;
                    case 7:
                        Intent intent7 = new Intent(balls.this, kiwifriut.class);
                        startActivity(intent7);
                        break;

                }

            }
        });
    }

    class myBaseAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int position) {
            return titles[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View view = View.inflate(balls.this, R.layout.listviewbujv, null);
            ImageView iv = view.findViewById(R.id.iv);
            TextView title = view.findViewById(R.id.title);
            TextView price = view.findViewById(R.id.price);

            iv.setBackgroundResource(icons[position]);
            title.setText(titles[position]);
            price.setText(prices[position]);

            return view;
        }
    }


}
